<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb20">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['enterprise:lesseeSource:add']"
        >新增
        </el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="名称" prop="lesseeSourceName">
        <el-input v-model="queryParams.lesseeSourceName" clearable placeholder="请输入名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="名称" prop="lesseeSourceName"/>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['enterprise:lesseeSource:edit']"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['enterprise:lesseeSource:remove']"
          >删除
          </el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <Add v-model="addDialogVisible" :title="title" :data="form" @success="getList"/>
  </div>
</template>

<script>
import { listElectronicVisaRecord } from '@/api/contract/electronicVisaRecord'
import { pageLesseeSource, deleteLesseeSource } from '@/api/contract/lesseeSource'

import Add from '@/views/long-short-rent/contract/lesseeSource/components/add.vue'

export default {
  name: 'lesseeSource',
  dicts: [],
  components: {
    Add
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 角色表格数据
      list: [],
      // 弹出层标题
      title: '',
      //表格行id
      id: undefined,
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 是否显示新建租客来源弹窗
      addDialogVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lesseeSourceName: '' //租客来源名称
      },
      showSearch:true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  computed: {},
  created() {
    this.getList()
  },
  methods: {
    /** 日期范围变化 */
    dateRangeChange(val) {
      if (val) {
        this.queryParams.startTime = val[0]
        this.queryParams.endTime = val[1]
      } else {
        this.queryParams.startTime = ''
        this.queryParams.endTime = ''
      }

    },
    /** 查询列表 */
    getList() {
      this.loading = true
      // listElectronicVisaRecord(this.addDateRange(this.queryParams, this.dateRange)).then(
      //   (response) => {
      //     this.list = response.rows
      //     this.total = response.total
      //     this.loading = false
      //   }
      // )
      // return
      pageLesseeSource(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.list = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.contractId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.title = '租客来源详情'
      this.addDialogVisible = true

    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.form = { ...row }
      this.title = '租客来源详情'
      this.addDialogVisible = true
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('<div style="text-align:center"><label style="font-size: 20px">确定删除数据？</label><div>确定后同步删除合同关联数据？</div></div>', {
        dangerouslyUseHTMLString: true
      }).then(() => {
        return deleteLesseeSource(row.lesseeSourceId).then((response) => {
          this.getList()
          this.$modal.msgSuccess(response.msg)
        }).catch((error) => {
        })
      })

    }
  }
}
</script>
<style lang="scss" scoped>

</style>
